<?php

require_once 'Zend/Cache.php';

class Helper_Cache
{
	/**
	 * @var array
	 */
	protected $_options = array();

	/**
	 * list of available cache
	 * @var array
	 */
	protected $_caches = array(
			'core' => null,
			'output' => null,
			'class' => null,
			'file' => null,
			'function' => null,
			'page' => null
	);

	/**
	 * set use cache when it done.
	 */
	protected $_cache = null;

	/**
	 * set name of cache.
	 * @param string $name lower case format
	 * @return Zend_Cache_Adapter
	 */
	public function useCache($name)
	{
		return $this -> _cache = $this -> getCache($name);
	}

	/**
	 * get cache
	 * @param string $name  lower case format, available options: core, class,
	 * output, page, ect.
	 * @return Zend_Cache_Adapter_Abstract
	 */
	public function getCache($name)
	{
		return $this -> _caches[$name] ? $this -> _caches[$name] : ($this -> _caches[$name] = $this -> _createCache($name));
	}

	/**
	 * constructor
	 */
	public function __construct()
	{
		$options =
		include SETTING_PATH . '/cache.php';

		$this -> _options = $options;
	}

	/**
	 * initialize
	 */
	protected function _createCache($name)
	{
		// match cache default or not.

		$options = isset($this -> _options[$name]) ? $this -> _options[$name] : $this -> _options['default'];

		$name = ucfirst($name);

		// make cache object
		return Zend_Cache::factory($name, $options['adapter'], $options['frontend'], $options['backend']);
	}

}
